home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form frmSample
- Caption = "Sample"
- ClientHeight = 3750
- ClientLeft = 60
- ClientTop = 345
- ClientWidth = 4425
- LinkTopic = "Form1"
- ScaleHeight = 3750
- ScaleWidth = 4425
- StartUpPosition = 3 'Windows Default
- Begin VB.CommandButton btnEndDoc
- Caption = "End Document"
- Enabled = 0 'False
- Height = 375
- Left = 120
- TabIndex = 11
- Top = 1560
- Width = 1695
- End
- Begin VB.Timer Timer
- Enabled = 0 'False
- Interval = 500
- Left = 3960
- Top = 2520
- End
- Begin VB.CommandButton btnSetup
- Caption = "Printer Setup"
- Height = 375
- Left = 120
- TabIndex = 9
- Top = 2640
- Width = 1695
- End
- Begin VB.CommandButton btnClose
- Cancel = -1 'True
- Caption = "Close"
- Height = 375
- Left = 120
- TabIndex = 4
- Top = 3240
- Width = 1695
- End
- Begin VB.CommandButton btnPreview
- Caption = "Preview Document"
- Enabled = 0 'False
- Height = 375
- Left = 120
- TabIndex = 3
- Top = 2040
- Width = 1695
- End
- Begin VB.CommandButton btnNewPage
- Caption = "New Page"
- Enabled = 0 'False
- Height = 375
- Left = 120
- TabIndex = 2
- Top = 1080
- Width = 1695
- End
- Begin VB.CommandButton btnDraw
- Caption = "Draw Page Items"
- Enabled = 0 'False
- Height = 375
- Left = 120
- TabIndex = 1
- Top = 600
- Width = 1695
- End
- Begin VB.CommandButton btnNewDoc
- Caption = "New Document"
- Height = 375
- Left = 120
- TabIndex = 0
- Top = 120
- Width = 1695
- End
- Begin VB.Label Label6
- AutoSize = -1 'True
- Caption = "Step 3: end the document"
- Height = 195
- Left = 2040
- TabIndex = 12
- Top = 1650
- Width = 1845
- End
- Begin VB.Label Label5
- Caption = "At any time, printer setup dialog may be shown"
- Height = 435
- Left = 2040
- TabIndex = 10
- Top = 2610
- Width = 2175
- End
- Begin VB.Label Label4
- AutoSize = -1 'True
- Caption = "Step 4: preview && print"
- Height = 195
- Left = 2040
- TabIndex = 8
- Top = 2130
- Width = 1590
- End
- Begin VB.Label Label3
- AutoSize = -1 'True
- Caption = "Step 2b: start a new page"
- Height = 195
- Left = 2040
- TabIndex = 7
- Top = 1170
- Width = 1830
- End
- Begin VB.Label Label2
- AutoSize = -1 'True
- Caption = "Step 2a: draw items on a page"
- Height = 195
- Left = 2040
- TabIndex = 6
- Top = 690
- Width = 2160
- End
- Begin VB.Label Label1
- AutoSize = -1 'True
- Caption = "Step 1: create a new document"
- Height = 195
- Left = 2040
- TabIndex = 5
- Top = 210
- Width = 2235
- End
- Attribute VB_Name = "frmSample"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Dim ppDoc As PreviewPrint.Document
- Dim nPage As Integer
- Private Sub btnClose_Click()
- Form_Unload False
- End
- End Sub
- Private Sub btnDraw_Click()
- Dim nCentre As Integer
- 'get the page center
- nCentre = ppDoc.PageWidth / 2
- 'draw the page title in black arial 24pt bold underline,
- 'centred and starting 25mm down from the page top
- ppDoc.SetTextColor vbBlack
- ppDoc.SetFont "Arial", 240, PPF_BOLD + PPF_UNDERLINE, 0
- ppDoc.SetTextAlign PPA_NOUPDATECP + PPA_CENTER + PPA_TOP
- ppDoc.TextOut nCentre, 250, "PreviewPrint: demo page " & nPage
- Dim nY As Integer, nSize As Integer
- Dim nWidth As Integer, nHeight As Integer
- nY = 520
- nSize = 50
- 'draw text in different colours inside this boxed area
- Dim nColor As Integer
- For nColor = 0 To 27
- ppDoc.SetTextColor RGB((nColor / 9) * 128, ((nColor / 3) Mod 3) * 128, (nColor Mod 3) * 128)
- ppDoc.SetFont "Arial", nSize, 0, 0
- ppDoc.TextOut nCentre, nY, "Arial, " & (nSize / 10) & " pt, color " & ppDoc.GetTextColor
- ppDoc.GetTextExtent "abc", nWidth, nHeight
- nY = nY + nHeight + 20
- nSize = nSize + 2
- Next
- 'draw a box surrounding the area that we will show different
- 'text colours, do the lines in different colors and styles
- ppDoc.MoveTo 500, 500
- ppDoc.SetLineStyle PPL_DASHDOTDOT, 0, vbYellow
- ppDoc.LineTo ppDoc.PageWidth - 500, 500
- ppDoc.SetLineStyle PPL_DASH, 0, vbRed
- ppDoc.LineTo ppDoc.PageWidth - 500, nY
- ppDoc.SetLineStyle PPL_DOT, 0, vbBlue
- ppDoc.LineTo 500, nY
- ppDoc.SetLineStyle PPL_DASHDOT, 0, vbGreen
- ppDoc.LineTo 500, 500
- 'demonstrate a clipped text output, draw the clipping rectangle
- ppDoc.SetLineStyle PPL_SOLID, 10, vbBlack
- ppDoc.MoveTo 250, nY + 100
- ppDoc.LineTo nCentre - 125, nY + 100
- ppDoc.LineTo nCentre - 125, nY + 400
- ppDoc.LineTo 250, nY + 400
- ppDoc.LineTo 250, nY + 100
- 'output clipped text
- ppDoc.SetTextColor vbBlue
- ppDoc.SetFont "Arial", 1200, PPF_BOLD, 0
- ppDoc.SetTextAlign PPA_NOUPDATECP + PPA_LEFT + PPA_BASELINE
- ppDoc.TextOutClip 250, nY + 400, "Clipped", _
- 250, nY + 100, nCentre - 125, nY + 400
- 'demonstrate a clipped text output, draw the clipping rectangle
- ppDoc.MoveTo nCentre + 125, nY + 100
- ppDoc.LineTo ppDoc.PageWidth - 250, nY + 100
- ppDoc.LineTo ppDoc.PageWidth - 250, nY + 400
- ppDoc.LineTo nCentre + 125, nY + 400
- ppDoc.LineTo nCentre + 125, nY + 100
- 'output clipped text
- ppDoc.SetTextColor RGB(0, 128, 0)
- ppDoc.SetFont "Arial", 120, PPF_BOLD, 0
- ppDoc.SetTextAlign PPA_NOUPDATECP + PPA_CENTER + PPA_TOP
- ppDoc.TextOutClip (3 * nCentre) / 2, nY + 150, _
- "Clipped Text Example With Long Text To Be Clipped Off Each End", _
- nCentre + 125, nY + 100, ppDoc.PageWidth - 250, nY + 400
- End Sub
- Private Sub btnEndDoc_Click()
- 'end the document
- ppDoc.EndDoc
- 'buttons
- btnNewDoc.Enabled = True
- btnNewPage.Enabled = False
- btnDraw.Enabled = False
- btnEndDoc.Enabled = False
- btnPreview.Enabled = True
- End Sub
- Private Sub btnNewDoc_Click()
- 'begin a new document
- ppDoc.BeginDoc
- ppDoc.SetTitle "Sample PreviewPrint Document", "PreviewPrintSample"
- ppDoc.StartPage = 1
- 'buttons
- btnNewDoc.Enabled = False
- btnNewPage.Enabled = True
- btnDraw.Enabled = True
- btnEndDoc.Enabled = True
- btnPreview.Enabled = False
- nPage = 1
- End Sub
- Private Sub btnNewPage_Click()
- 'start a new page now
- ppDoc.NewPage
- nPage = nPage + 1
- End Sub
- Private Sub btnPreview_Click()
- 'hide ourselves while the preview window is shown
- Me.Hide
- 'show the preview window and start the timer which will
- 'check to see when we should show ourselves again
- ppDoc.ShowPreview
- Timer.Enabled = True
- End Sub
- Private Sub btnSetup_Click()
- 'show the printer setup
- ppDoc.ShowPrintSetup
- End Sub
- Private Sub Form_Load()
- On Error GoTo errLoad
- 'ensure that we show ourselves before we load the
- 'previewprint object, show the hourglass while we do so
- Me.Show
- Screen.MousePointer = vbHourglass
- DoEvents
- 'create the ole automation server object, we will use this
- 'object to draw all of our pages and never touch the VB
- 'printer object again
- Set ppDoc = New PreviewPrint.Document
- Screen.MousePointer = vbDefault
- 'set the initial values
- ppDoc.hwndOwner = Me.hWnd
- ppDoc.Orientation = PPO_PORTRAIT
- Exit Sub
- errLoad:
- Screen.MousePointer = vbDefault
- MsgBox _
- "Unable to create the PreviewPrint object. " _
- & "Ensure it has been registered by running the program once. " _
- & Err.Description
- End
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- 'destroy the ole automation server object
- ppDoc.KillDoc 'not strictly necessary
- Set ppDoc = Nothing
- End Sub
- Private Sub Timer_Timer()
- Dim nState As Integer
- 'while we are still in the preview state, do nothing
- nState = ppDoc.PreviewPrintState
- If nState <> PPS_PREVIEW Then
- 'we've stopped previewing, so now we are either printing
- 'or we have cancelled the print/preview and are returned
- 'to our main app. Cancel the timer and make ourselves
- 'visible
- Timer.Enabled = False
- Me.Visible = True
-
- 'if we are about to print, then we need to set our zorder
- 'so that we are behind the print dialog, otherwise if we
- 'are idle again then we want to move to the front of the zorder
- 'and get the focus again
- If nState = PPS_PRINT Then
- Me.ZOrder 1
- Else
- Me.ZOrder
- Me.SetFocus
- End If
- End If
- End Sub
-